package ${entity.namespace}.${prefixPackage};

import ${entity.namespace}.entity.${entity.nameCapital};
import ${entity.namespace}.service.${entity.nameCapital}Service;
import com.fzy.core.U;
import com.fzy.core.BaseAction;
import com.fzy.core.MyValidationAware;
import com.opensymphony.xwork.ModelDriven;
import com.opensymphony.xwork.Preparable;

public class ${entity.nameCapital}InputAction extends BaseAction implements ModelDriven, 
		MyValidationAware, Preparable {
	private static final long serialVersionUID = ${statics["com.fzy.core.codetools.Utils"].getRandomLong()};
	
	${entity.nameCapital} ${entity.nameUncapital};
	${entity.nameCapital}Service ${entity.nameUncapital}Service;
	String errorDispatch;

	public void prepare() throws Exception {
		errorDispatch = "redirect:list.do";
		${entity.nameUncapital} = (${entity.nameCapital})validateIdAndGetEntity(request.getParameter("id"), ${entity.nameCapital}.class);
        // default values
        if(${entity.nameUncapital} == null){
        	${entity.nameUncapital} = new ${entity.nameCapital}();
<#list entity.properties as property><#t/>
<#if property.hasDefaultValue><#t/>
	<#if statics["com.fzy.core.codetools.PropertyWrapper"].STRING == property.propertyType><#t/>
			${entity.nameUncapital}.set${property.nameCapital}("${property.defaultValue}");
	</#if><#t/>
	<#if statics["com.fzy.core.codetools.PropertyWrapper"].LONG == property.propertyType><#t/>
			${entity.nameUncapital}.set${property.nameCapital}(U.string2longObj("${property.defaultValue}"));
	</#if><#t/>
	<#if statics["com.fzy.core.codetools.PropertyWrapper"].NUMBER == property.propertyType><#t/>
			${entity.nameUncapital}.set${property.nameCapital}(U.string2doubleObj("${property.defaultValue}"));
	</#if><#t/>
	<#if statics["com.fzy.core.codetools.PropertyWrapper"].DATE == property.propertyType><#t/>
			${entity.nameUncapital}.set${property.nameCapital}(U.string2date("${property.defaultValue}"));
	</#if><#t/>
</#if><#t/>
</#list><#t/>
        }
	}

	public void validate() {

	}

	public String execute() throws Exception {
		return "dispatcher:/WEB-INF/jsp/ge/${entity.moduleName}/${entity.nameUncapital}-input.jsp";
	}

	public void set${entity.nameCapital}Service(${entity.nameCapital}Service ${entity.nameUncapital}Service) {
		this.${entity.nameUncapital}Service = ${entity.nameUncapital}Service;
	}

	public ${entity.nameCapital} get${entity.nameCapital}() {
		return ${entity.nameUncapital};
	}

	public Object getModel() {
		return ${entity.nameUncapital};
	}

	public String getErrorDispatch() {
		return errorDispatch;
	}

}
